<?php

namespace app\model;

use think\Model;

class SystemMenuDataPower extends Model
{

    /**
     * 菜单&数据可见范围表
     */

    protected $createTime='create_date';

    public function addMenuPowerModel($data)
    {
        return self::create ($data);
    }

    public function getPositionDataDetails($id)
    {
        return $this->where (['roles_id'=>$id])->find ();
    }

    public function getPositionDataRangeModel($id)
    {
        return $this->where (['roles_id'=>$id])->value ('data_range');
    }

    /**
     * 查询职位是否有对应菜单权限
     * @param $id
     * @return array|bool
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */

    public function getPotionData($id)
    {
        $data = $this->where (['roles_id'=>$id])->findOrEmpty ();
        if (!$data->isEmpty ()){
            return $data->toArray ();
        }
        return null;
    }


    public function editPositionData($roles_id,$data)
    {
        return $this->where (['roles_id'=>$roles_id])->update ($data);
    }

    /**
     * 数据可见范围
     * @param $range
     * @return mixed
     */
    public function getDataRangeModel($range)
    {
        return $this->where (['roles_id'=>$range])->value ('data_range');
    }
}